<template>
    <div style="width: 95%">
        <div style="margin-bottom: 30px">新增课程</div>
        <el-form :inline="true" :model="form" label-width="100px" :rules="rules" ref="ruleForm">
            <el-form-item label="课程名" prop="courseName">
                <el-input v-model="form.courseName" placeholder="请输入课程名"></el-input>
            </el-form-item>
            <el-form-item label="课程代码" prop="courseCode">
                <el-input v-model="form.courseCode" placeholder="请输入课程代码"></el-input>
            </el-form-item>
            <el-form-item label="开始周" prop="begin">
                <el-select v-model="form.begin" placeholder="请选择开始周">
                    <el-option label="第一周" value="1"></el-option>
                    <el-option label="第二周" value="2"></el-option>
                    <el-option label="第三周" value="3"></el-option>
                    <el-option label="第四周" value="4"></el-option>
                    <el-option label="第五周" value="5"></el-option>
                    <el-option label="第六周" value="6"></el-option>
                    <el-option label="第七周" value="7"></el-option>
                    <el-option label="第八周" value="8"></el-option>
                    <el-option label="第九周" value="9"></el-option>
                    <el-option label="第十周" value="10"></el-option>
                    <el-option label="第十一周" value="11"></el-option>
                    <el-option label="第十二周" value="12"></el-option>
                    <el-option label="第十三周" value="13"></el-option>
                    <el-option label="第十四周" value="14"></el-option>
                    <el-option label="第十五周" value="15"></el-option>
                    <el-option label="第十六周" value="16"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="结束周" prop="end">
                <el-select v-model="form.end" placeholder="请选择结束周">
                    <el-option label="第一周" value="1"></el-option>
                    <el-option label="第二周" value="2"></el-option>
                    <el-option label="第三周" value="3"></el-option>
                    <el-option label="第四周" value="4"></el-option>
                    <el-option label="第五周" value="5"></el-option>
                    <el-option label="第六周" value="6"></el-option>
                    <el-option label="第七周" value="7"></el-option>
                    <el-option label="第八周" value="8"></el-option>
                    <el-option label="第九周" value="9"></el-option>
                    <el-option label="第十周" value="10"></el-option>
                    <el-option label="第十一周" value="11"></el-option>
                    <el-option label="第十二周" value="12"></el-option>
                    <el-option label="第十三周" value="13"></el-option>
                    <el-option label="第十四周" value="14"></el-option>
                    <el-option label="第十五周" value="15"></el-option>
                    <el-option label="第十六周" value="16"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div style="text-align: center; margin-top: 30px">
            <el-button type="primary" @click="save" size="medium">提交</el-button>
        </div>
    </div>
</template>

<script>

    import request from "../../utils/request";

    export default {
        name: "add",
        data() {
            return {
                form: {},
                //表单校验规则
                rules: {
                    courseName: [
                        { required: true, message: '请输入课程名', trigger: 'blur'}
                    ],
                    courseCode: [
                        { required: true, message: '请输入课程码', trigger: 'blur'}
                    ],
                    begin: [
                        { required: true, message: '请选择开始周', trigger: 'blur'}
                    ],
                    end: [
                        { required: true, message: '请选择结束周', trigger: 'blur'}
                    ],
                }
            }
        },
        methods: {
            save() {
                this.$refs['ruleForm'].validate((valid) => {
                    if (valid) {
                        request.post("/course/add",this.form).then(res => {
                            if (res.code === '200'){
                                this.$notify.success("新增成功");
                                //this.form = {};       这两种方式都是用来清空form
                                this.$refs['ruleForm'].resetFields();
                                this.$router.push('/course/list');
                            } else {
                                this.$notify.error(res.msg);
                            }
                        })
                    }
                })
            }
        }
    }
</script>

